package com.cc.service.impl;

import com.cc.entity.Categories;
import com.cc.entity.CategoriesList;
import com.cc.mapper.CategoriesMapper;
import com.cc.service.CategoriesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoriesServiceImpl implements CategoriesService {

    @Autowired
    CategoriesMapper categoriesMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param categoryId 主键
     * @return 实例对象
     */
    @Override
    public Categories queryById(Integer categoryId) {
        return categoriesMapper.queryById(categoryId);
    }

    /**
     * 分页查询
     *
     * @param categories 筛选条件
     * @return 查询结果
     */
    @Override
    public PageInfo<Categories> queryByPage(Categories categories, Integer pageNum) {
        PageHelper.startPage(pageNum, 5);
        List<Categories> list = categoriesMapper.queryAllByLimit(categories);
        PageInfo<Categories> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param categories 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Categories categories) {
        return categoriesMapper.insert(categories);
    }

    /**
     * 修改数据
     *
     * @param categories 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Categories categories) {
        return categoriesMapper.update(categories);
    }

    /**
     * 通过主键删除数据
     *
     * @param categoryId 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer categoryId) {
        return categoriesMapper.deleteById(categoryId);
    }

    @Override
    public List<CategoriesList> list() {
        return categoriesMapper.list();
    }
}
